<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>小米商城-个人中心</title>
		<link rel="stylesheet" type="text/css" href="./css/style.css">
		<script src="js/jquery-3.5.1.js" type="application/javascript"></script>
		<script src="js/js.cookie.js" type="application/javascript"></script>
		<script type="text/javascript">
			var a=null;
			$(document).ready(function () {
				$.ajax({
					type: "post",
					dataType: "json",
					url: "GetLoginInfoController",
					success: function (data) {
						//alert(data.result);
						if (data.result != "0") {
							a=data.result;
							$("#current_user").empty();
							var str= "<ul>"
									+"<li><a id='current_username' href='self_info' target='_blank'>"+data.result+"</a></li>"
									+"<li>|</li>"
									+"<li><a href=''>订单通知</a></li>"
									+"</ul>";
							$("#current_user").append(str);
							var userinfo=data.userinfo;
							showinfo(userinfo);
						}  else {
							var url = "login";
							Cookies.remove('login_name');
							Cookies.remove('login_pwd');
							location.href = encodeURI(url
									+ "?tip=");
						}
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						// 状态码
						console.log(XMLHttpRequest.status);
						// 状态
						console.log(XMLHttpRequest.readyState);
						// 错误信息
						console.log(textStatus);
					}
				});
			});

			
			function setnewinfo(data) {
				$("#myinfo").empty();
				var str="<div class='grzlbt ml40'>我的资料</div>"
						+"<div class='subgrzl ml40'><span>昵称</span><span><input id='nickname' class='shurukuang' type='text' value='2'/></span></div>"
				+"<div class='subgrzl ml40'><span>手机号</span><span><input id='phonenum' class='shurukuang' type='text' value='3'/></span></div>"
				+"<div class='subgrzl ml40'><span>密码</span><span><input id='userpwd' class='shurukuang' type='text' value='4'/></span></div>"
				+"<div class='subgrzl ml40'><span>收货地址</span><span><input id='deliveryaddress' class='shurukuang' type='text' value='5'/></span></div>"
				+"<div class='login_submit'>"
						+"<input class='submit' type='button' name='submit' value='保存' onclick='updateinfo()'>"

						+"</div>";
				$("#myinfo").append(str);
			}
			function updateinfo() {
				var username=a;
				alert(username);
				var userpwd=$("#userpwd").val();
				var nickname=$("#nickname").val();
				var phonenum=$("#phonenum").val();
				var deliveryaddress=$("#deliveryaddress").val();
				$.ajax({
					type:"post",
					dataType: "json",
					url:"UpdateProductController",
					data:{
						"username":username,
						"userpwd":userpwd,
						"nickname":nickname,
						"phonenum":phonenum,
						"deliveryaddress":deliveryaddress
					},
					success:function (data) {
						if(data.result=='1'){
							var url="self_info";
							location.href=url;
						}else{
							var url="self_info";
							location.href=encodeURI(url+"?tip=用户信息丢失，更新失败");
						}
					}
				});
			}
			function showinfo(data) {
				$("#myinfo").empty();
				var str="<div class='grzlbt ml40'>我的资料</div>"
						+"<div class='jsanniu fr'><input class='jsan' type='submit' name='jiesuan' onclick='setnewinfo()' value='修改个人信息'/></div>"
						+"<div class='subgrzl ml40'><span>昵称</span><span>"+data.nickname+"</span></div>"
						+"<div class='subgrzl ml40'><span>手机号</span><span>"+data.phonenum+"</span></div>"
						+"<div class='subgrzl ml40'><span>密码</span><span>************</span></div>"
						+"<div class='subgrzl ml40'><span>收货地址</span><span>"+data.deliveryaddress+"</span></div>"
						+"<button id='logout' onclick='logout()'>退出</button>";
				$("#myinfo").append(str);
			}
			function logout() {
				$.ajax({
					type: "post",
					dataType: "json",
					url: "LogoutController",
					success:function (data) {
						if(data.result=="1"){
							Cookies.remove('login_name');
							Cookies.remove('login_pwd');
							var url = "index";
							location.href = encodeURI(url + "?tip=退出成功，谢谢使用！！");
						}
					},
					error:function () {
						alert("系统出现问题!!!");
					}
				});
			};

		</script>
	</head>
	<body>
	<!-- start header -->
		<header>
			<div class="top center">
				<div class="left fl">
					<ul>
						<li><a href="./index.html" target="_blank">小米商城</a></li>
						<li>|</li>
						<li><a href="">MIUI</a></li>
						<li>|</li>
						<li><a href="">米聊</a></li>
						<li>|</li>
						<li><a href="">游戏</a></li>
						<li>|</li>
						<li><a href="">多看阅读</a></li>
						<li>|</li>
						<li><a href="">云服务</a></li>
						<li>|</li>
						<li><a href="">金融</a></li>
						<li>|</li>
						<li><a href="">小米商城移动版</a></li>
						<li>|</li>
						<li><a href="">问题反馈</a></li>
						<li>|</li>
						<li><a href="">Select Region</a></li>
						<div class="clear"></div>
					</ul>
				</div>
				<div class="right fr">
					<div class="gouwuche fr"><a href="order_center">我的订单</a></div>
					<div class="fr" id="current_user">
						<ul>
							<li><a href="./login.html" target="_blank">登录</a></li>
							<li>|</li>
							<li><a href="./register.html" target="_blank" >注册</a></li>
							<li>|</li>
							<li><a href="#top">个人中心</a></li>
						</ul>
					</div>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
			</div>
		</header>
	<!--end header -->
	<!-- start banner_x -->
		<div class="banner_x center">
			<a href="./index.html" target="_blank"><div class="logo fl"></div></a>
			<a href=""><div class="ad_top fl"></div></a>
			<div class="nav fl">
				<ul>
					<li><a href="">小米手机</a></li>
					<li><a href="">红米</a></li>
					<li><a href="">平板·笔记本</a></li>
					<li><a href="">电视</a></li>
					<li><a href="">盒子·影音</a></li>
					<li><a href="">路由器</a></li>
					<li><a href="">智能硬件</a></li>
					<li><a href="">服务</a></li>
					<li><a href="">社区</a></li>
				</ul>
			</div>
			<div class="search fr">
				<form action="" method="post">
					<div class="text fl">
						<input type="text" class="shuru"  placeholder="小米6&nbsp;小米MIX现货">
					</div>
					<div class="submit fl">
						<input type="submit" class="sousuo" value="搜索"/>
					</div>
					<div class="clear"></div>
				</form>
				<div class="clear"></div>
			</div>
		</div>
<!-- end banner_x -->
<!-- self_info -->
	<div class="grzxbj">
		<div class="selfinfo center">
		<div class="lfnav fl">
			<div class="ddzx">订单中心</div>
			<div class="subddzx">
				<ul>
					<li><a href="order_center" >我的订单</a></li>
					<li><a href="">意外保</a></li>
					<li><a href="">团购订单</a></li>
					<li><a href="">评价晒单</a></li>
				</ul>
			</div>
			<div class="ddzx">个人中心</div>
			<div class="subddzx">
				<ul>
					<li><a href="./self_info.html" style="color:#ff6700;font-weight:bold;">我的个人中心</a></li>
					<li><a href="">消息通知</a></li>
					<li><a href="">优惠券</a></li>
					<li><a href="">收货地址</a></li>
				</ul>
			</div>
		</div>
		<div class="rtcont fr" id="myinfo">
			<div class="grzlbt ml40">我的资料</div>
			<div class="jsanniu fr"><input class="jsan" type="submit" name="jiesuan" onclick="setnewinfo()" value="修改个人信息"/></div>
			<div class="subgrzl ml40"><span>昵称</span><span><input class="shurukuang" type="text" value="啦啦维吉尔"/> </span></div>
			<div class="subgrzl ml40"><span>手机号</span><span>15669097417</span></div>
			<div class="subgrzl ml40"><span>密码</span><span>************</span></div>
			<div class="subgrzl ml40"><span>个性签名</span><span>一支穿云箭，千军万马来相见！</span></div>
			<div class="subgrzl ml40"><span>我的爱好</span><span>游戏，音乐，旅游，健身</span></div>
			<div class="subgrzl ml40"><span>收货地址</span><span>浙江省杭州市江干区19号大街571号</span></div>
			<div class="login_submit">
				<input class="submit" type="button" name="submit" value="保存" onclick="saveinfo()">
			</div>
		</div>
			<div class="gouwuche fr"><button>退出登录</button></div>
		<div class="clear"></div>
		</div>
	</div>
<!-- self_info -->
		
		<footer class="mt20 center">			
			<div class="mt20">小米商城|MIUI|米聊|多看书城|小米路由器|视频电话|小米天猫店|小米淘宝直营店|小米网盟|小米移动|隐私政策|Select Region</div>
			<div>©mi.com 京ICP证110507号 京ICP备10046444号 京公网安备11010802020134号 京网文[2014]0059-0009号</div> 
			<div>违法和不良信息举报电话：185-0130-1238，本网站所列数据，除特殊说明，所有数据均出自我司实验室测试</div>
		</footer>
	</body>
</html>